package functional
{
	import baseInterface.container.IBaseSkinContainer;
	import baseInterface.functional.Iable;
	import baseInterface.functional.IenableAble;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	
	import skin.BaseSkin;

	/**
	 * 能否被选择
	 * @author Chita
	 * 
	 */	
	public class ADbaseAble implements Iable
	{
		private var _enable:Boolean=false;
		private var _doit:Boolean=false;
		private var func:Function=statefu;
		protected var event:String;
		protected var targetCom:IenableAble;
		public function ADbaseAble()
		{
		}
		public function set isable(value:Boolean):void
		{
			_enable=value;
		}
		
		public function get isable():Boolean
		{
			return _enable;
		}
		
		public function set isDoit(value:Boolean):void
		{
			value=_doit;
		}
		
		public function get isDoit():Boolean
		{
			return _doit;
		}
		public function set stateFunc(func:Function):void
		{
			var index:int=targetCom.getStateFuncIndex(this.func);
			this.func=func;
			if(targetCom&&index>=0)
			{
				targetCom.defineState(index,this.func);
			}
		}
		public function get stateFunc():Function
		{
			return func;
		}
		private function statefu(skins:*, index:int):void
		{
			for each (var i:BaseSkin in skins) 
			{
				i.visible=skins.indexOf(i)==index
			}
		}
		public 	function setTarget(target:IenableAble):void
		{
			target.addEventListener(event,eventHandle);
			targetCom=target;
		}
		protected function eventHandle(e:Event):void
		{
			if(!isable)return ;
			var _com:IenableAble=e.currentTarget as IenableAble;
			isDoit=true;
			_com.state=_com.getStateFuncIndex(stateFunc);
		}
	}
}